package com.emeraldparser.parse;

import com.emeraldparser.symbol.SymbolClass;
import com.emeraldparser.symbol.SymbolClass.State;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;

public class ParseState {

	private final ImmutableSet<? extends SymbolClass.State> downStates;
	private final ImmutableSet<? extends SymbolClass.State> upStates;

	public ParseState(Iterable<? extends State> downStates, Iterable<? extends State> upStates) {
		this(ImmutableSet.copyOf(downStates), ImmutableSet.copyOf(upStates));
	}

	public ParseState(ImmutableSet<? extends State> downStates, ImmutableSet<? extends State> upStates) {
		this.downStates = downStates;
		this.upStates = upStates;
	}

	public ImmutableSet<? extends SymbolClass.State> downStates() {
		return downStates;
	}

	public ImmutableSet<? extends SymbolClass.State> upStates() {
		return upStates;
	}

	@Override
	public String toString() {
		return "ParseState [downStates=" + downStates + ", upStates=" + upStates + "]";
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(downStates, upStates);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		
		if (obj == null) {
			return false;
		}
		
		if (getClass() != obj.getClass()) {
			return false;
		}
		
		ParseState other = (ParseState) obj;
		
		return Objects.equal(downStates, other.downStates)
		    && Objects.equal(upStates, other.upStates);
	}

}
